# 导包
import unittest
from api.goods import GoodAPI


# 创建测试类
class TestGoodsAPI(unittest.TestCase):
    # 初始化
    # 商品分类id
    id6 = None
    # 商品id
    id8 = None

    # 前置处理
    def setUp(self) -> None:
        # 实例化接口类
        self.goods_api = GoodAPI()

    # 后置处理
    def tearDown(self) -> None:
        pass

    # 获取商品分类
    def test01_get_list(self):
        response = self.goods_api.get_list()
        # 打印响应数据
        print(response.json())
        # 提取商品分类id并保存至类的属性
        TestGoodsAPI.id666 = response.json()[1].get("id")
        print(TestGoodsAPI.id666)

    # 获取分类下商品
    def test02_get_goods_under_list(self):
        response = self.goods_api.get_goods_under_list(TestGoodsAPI.id6)
        # 打印响应数据
        print(response.json())
        # 提取商品id并保存至类的属性
        TestGoodsAPI.id888 = response.json()[0].get("id")
        print(TestGoodsAPI.id888)

    # 获取商品详情
    def test03_get_goods(self):
        response = self.goods_api.get_goods_info(TestGoodsAPI.id8)
        # 打印响应数据
        print(response.json())
